<!-- 表达式选择 -->
<template>
  <t-dialog header="请选择表达式" v-model:visible="dialogVisible" width="1024px">
    <t-card>
      <t-table v-loading="loading" :data="list" :columns="columns" size="small" bordered :stripe="true" :show-overflow-tooltip="true">

      <template #operation="{ row ,rowIndex }">
        <t-link size="small" style="margin-right: 4px;" theme="primary" @click="select(row)"
          >选择</t-link>
            
        
      </template>
        
      </t-table>
      <!-- 分页 -->
      <t-pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </t-card>
  </t-dialog>
</template>
<script setup lang="ts">
import { processExpressionCRUD, ProcessExpressionVO } from '@/api/bpm/process-expression'
import { TableCol } from 'tdesign-vue-next'
import { reactive, ref } from 'vue'

/** BPM 流程 表单 */
defineOptions({ name: 'ProcessExpressionDialog' })

const dialogVisible = ref(false) // 弹窗的是否展示
const loading = ref(true) // 列表的加载中
const list = ref<ProcessExpressionVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  type: '',
  status: 0
})

/** 打开弹窗 */
const open = (type: string) => {
  queryParams.pageNo = 1
  queryParams.type = type
  getList()
  dialogVisible.value = true
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await processExpressionCRUD.page(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
const columns: TableCol[] = [
  { colKey: 'name', title: '名字'},
  { colKey: 'expression', title: '表达式' },
  { colKey: 'operation', title: '操作', width: 100, fixed: 'right' },
].map(column => ({ ...column, align: 'center' }));
/** 提交表单 */
const emit = defineEmits(['success','select']) // 定义 success 事件，用于操作成功后的回调
const select = async (row:any) => {
  dialogVisible.value = false
  // 发送操作成功的事件
  emit('select', row)
}
</script>
